cmake_minimum_required(VERSION 3.16)
project(sokit VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Qt6 配置
find_package(Qt6 REQUIRED COMPONENTS Widgets Network LinguistTools)

# 启用AUTOMOC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# 设置源文件
set(SOURCES
    src/sokit/baseform.cpp
    src/sokit/helpform.cpp
    src/sokit/logger.cpp
    src/sokit/main.cpp
    src/sokit/setting.cpp
    src/sokit/toolkit.cpp
    src/sokit/transferform.cpp
    src/sokit/transferskt.cpp
)

set(HEADERS
    src/sokit/resource.h
    src/sokit/setting.h
    src/sokit/toolkit.h
    src/sokit/baseform.h
    src/sokit/helpform.h
    src/sokit/logger.h
    src/sokit/main.h
    src/sokit/transferskt.h
    src/sokit/transferform.h
)

set(FORMS
    src/sokit/helpform.ui
    src/sokit/transferform.ui
)

set(RESOURCES
    src/sokit/icons.qrc
    src/sokit/styles.qrc
)

set(TRANSLATIONS
    src/sokit/sokit.ts
)

# 创建GUI可执行文件
qt_add_executable(sokit
    ${SOURCES}
    ${HEADERS}
    ${FORMS}
    ${RESOURCES}
    ${TRANSLATIONS}
)

# 链接 Qt6 库
target_link_libraries(sokit PRIVATE
    Qt6::Widgets
    Qt6::Network
)

# 设置包含目录
target_include_directories(sokit PRIVATE
    src/sokit
)

# 创建命令行版本
set(CLI_SOURCES
    src/sokit-cli/main.cpp
    src/sokit-cli/setting.cpp
    src/sokit-cli/toolkit.cpp
    src/sokit/transferskt.cpp
)

set(CLI_HEADERS
    src/sokit-cli/setting.h
    src/sokit-cli/toolkit.h
    src/sokit/transferskt.h
)

qt_add_executable(sokit-cli
    ${CLI_SOURCES}
    ${CLI_HEADERS}
)

# 链接命令行版本的Qt6库
target_link_libraries(sokit-cli PRIVATE
    Qt6::Core
    Qt6::Network
)

# 设置命令行版本的包含目录
target_include_directories(sokit-cli PRIVATE
    src/sokit
    src/sokit-cli
)

# Windows 特定配置
if(WIN32)
    set_target_properties(sokit PROPERTIES
        WIN32_EXECUTABLE TRUE
    )
    
    # Windows 资源文件
    if(EXISTS "src/sokit/sokit.rc")
        target_sources(sokit PRIVATE src/sokit/sokit.rc)
    endif()
    
    # Windows 库链接
    target_link_libraries(sokit PRIVATE
        ws2_32
        winmm
        imm32
    )
endif()

# 编译选项
target_compile_definitions(sokit PRIVATE
    QT_NETWORK_LIB
    $<$<CONFIG:Debug>:QT_DEBUG>
)

# 安装配置
install(TARGETS sokit sokit-cli
    RUNTIME DESTINATION bin
    BUNDLE DESTINATION .
)

# 翻译文件处理
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TRANSLATIONS})
target_sources(sokit PRIVATE ${QM_FILES})

# 设置输出目录
set_target_properties(sokit PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/debug
    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/release
)

set_target_properties(sokit-cli PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/debug
    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/release
) 